package com.eric.statemachinedemo.listener;

import com.eric.statemachinedemo.config.RmaStateMachineConfig;
import com.eric.statemachinedemo.constant.RmaEventEnum;
import com.eric.statemachinedemo.constant.RmaStatusEnum;
import com.eric.statemachinedemo.model.request.ProcessRequestData;
import com.eric.statemachinedemo.strategy.RmaProcessExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.annotation.*;
import org.springframework.stereotype.Component;

@Component
@WithStateMachine(id=RmaStateMachineConfig.MACHINE_ID)
public class RmaStateMachineListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(RmaStateMachineListener.class);

    /**
     * 事件未被接受，即没有发布
     * 适用于任何事件
     */
    @OnEventNotAccepted
    public void anyEventNotAccepted(StateContext<RmaStatusEnum, RmaEventEnum> stateContext) {
        LOGGER.info("事件未被接收...");
    }

    /**
     * 监听所有状态转换
     * @param stateContext
     */
    @OnTransition
    public void anyTransition(StateContext<RmaStatusEnum, RmaEventEnum> stateContext) {
        LOGGER.info("状态转换...");
    }

    /**
     * 事件处理发生异常, setStateMachineError时触发
     * 适用于任何事件
     */
    @OnStateMachineError
    public void error(StateContext<RmaStatusEnum, RmaEventEnum> stateContext){
        LOGGER.info("发生异常...");
    }
}

